package org.walkerljl.commons.trace;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 调用信息
 *
 * @author lijunlin
 * @Date 2016/11/25
 */
public class InvocationInfo implements Serializable {

    public static final int STATE_SUCCESS = 1;
    public static final int STATE_FAILURE = -1;

    private String appCode;
    private Class<?> objectClass;
    private String methodName;
    private Object[] request;
    private Object response;
    private String description;
    private int state = STATE_SUCCESS;
    private Throwable throwable;
    private long startTime = System.currentTimeMillis();
    private long endTime = 0;
    private Map<String, Object> parametersMap = new HashMap<String, Object>(0);

    public InvocationInfo(Class<?> objectClass, String methodName, String description, Object[] request) {
        this.objectClass = objectClass;
        this.methodName = methodName;
        this.description = description;
        this.request = request;
    }

    public void setFailure() {
        this.setFailure(null);
    }

    public void setFailure(Throwable throwable) {
        this.state = STATE_FAILURE;
        this.throwable = throwable;
        this.endTime = System.currentTimeMillis();
    }

    public void setSuccess() {
        this.state = STATE_SUCCESS;
        this.endTime = System.currentTimeMillis();
    }


    public void addParameter(String key, Object value) {
        parametersMap.put(key, value);
    }

    public String getAppCode() {
        return appCode;
    }

    public void setAppCode(String appCode) {
        this.appCode = appCode;
    }

    public Class<?> getObjectClass() {
        return objectClass;
    }

    public void setObjectClass(Class<?> objectClass) {
        this.objectClass = objectClass;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public Object[] getRequest() {
        return request;
    }

    public void setRequest(Object[] request) {
        this.request = request;
    }

    public Object getResponse() {
        return response;
    }

    public void setResponse(Object response) {
        this.response = response;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }
}
